<template>
  <div class="template">
    <hunk-head icon="home" name='托管的房源'></hunk-head>
    <!-- <uni-segmented-control :current="current" :values="items" @clickItem="onClickItem" styleType="text" activeColor="#FFAA58"></uni-segmented-control> -->
      <div class="linkList">
        <div class="list-item" v-for="(item, index) in linkList" :key="index">
        <!-- <div class="list-item"> -->
          <div class="leftImg">
            <img :src="item.defaultimg" alt="" srcset="">
            <div :class="['leftTop', item.islease ? 'red':'green']">{{ item.islease ? '已租':'未租'}}</div>
          </div>
          <div class="rightText">
            <div class="text-top">
              {{item.outtype ? '整租':'合租'}}-{{item.housetitle}}
              <!-- 整租-天星美和园公寓3栋-二单元-302 -->
            </div>
            <div class="time">
              {{item.roomarea}}m²/{{item.roomtype}}室/{{item.renovation}}
              <!-- 10m²/1室/简装修 -->
            </div>
            <div class="money">
              <span>{{item.lowrent}}元</span>
              /月
            </div>
          </div>
        </div>
      </div>
      <div class="bextBtn" @click="checktuoguan">确认</div>
    <uni-popup ref="popup1" type="center">
      <div class="tips1">
        <div class="tips-top">认证授权</div>
        <div class="tips-text">尊敬的用户，您还未进行实名认证，是否进行实名认证</div>
        <div class="tips-btn">
          <div class="btn-closs" @click="closePopup1">取消</div>
          <div  @click="gorenzheng">确认</div>
        </div>
      </div>
    </uni-popup>
    <uni-popup ref="approve" type="center">
      <div class="tips2">
        <div class="tips-top">提示</div>
        <div class="tips-text">尊敬的用户，您还未进行用户授权，是否进行用户授权？</div>
        <div class="tips-btn">
          <div class="btn-closs" @click="closeP">取消</div>
          <div  @click="checkedP">确认</div>
        </div>
      </div>
    </uni-popup>
  </div>
</template>

<script>
import Head from '@componentsMine/head'
import { housetrusteeship } from '@/apis/host'
import { getSharHouseList } from '@/apis/share'
import store from '@store/index'
import {GetUserInfo_openid,getuseropenid} from '@/apis/user'
export default {
  components: {
    'hunk-head': Head
  },
  data() {
    return {
      // current:0,
      // items: [ '整租', '合租' ],
      linkList:[
      ],
      name:'',
      houseList:[],
      limit:100,
      offset: 1,
      clickInfo:[]
    }
  },
  computed:{
    userInfo() {
      return this.$store.state.baseStore.userInfo
    }
    // outtype(){
    //   if(this.current){
    //     return 0
    //   }else{
    //     return 1
    //   }
    // }
  },
  onLoad(e){
    let data = JSON.parse(e.query)
    // this.name = data.name
    this.houseList = data.houseLit
    // let that = this
    // list.forEach(element => {
    //   element.houseLists.forEach((item,idx)=>{
    //       if(item.checked){
    //         that.houseList.push(item.houseroomid)
    //       }
    //     })
    // })
    this.isShouquan()
    this.getSharHouseList()
  },
  created(){
  },
  methods: {
    checkedP(){
      this.$refs.approve.close()
      uni.navigateTo({ url: '/subPackage/link/approve' })
    },
    closeP(){
      this.$refs.approve.close()
      uni.reLaunch({ url: '/pages/login/checkUser' })
    },
    closePopup1(){
      this.$refs.popup1.close()
    },
    // onClickItem(e){
    //   this.current = e.currentIndex
    //   this.getSharHouseList()
    // },
    checktuoguan(){
      let user = this.$store.state.baseStore.userInfo
      if(!user.userid){
        this.$refs.approve.open()
        return
      }
      if(this.userInfo.cardid){
        this.housetrusteeship()
      }else{
        this.$refs.popup1.open()
      }
    },
    gorenzheng(){
      this.$refs.popup1.close()
      uni.navigateTo({ url: '/subPackage/link/renzheng' })
      // this.$jump({path:'/pages/link/renzheng'})
    },
    getSharHouseList(){
      let that = this
      let data = {
        limit: 100,
        offset: 1,
        wids:this.houseList.join(','),
        outtype: 0
      }
      getSharHouseList(data).then(res=>{
        if(res.code == 200){
          // this.linkList = res.data
          if (that.offset === 1) {
            that.linkList = res.data
          }else if(that.linkList.length >= res.total){
            return
          } else {
            that.linkList = that.linkList.concat(res.data)
          }
          that.$forceUpdate()
        }
      })
    },
    housetrusteeship(){
      let list = []
      this.linkList.forEach((item,idx)=>{
        list.push({
          houseid:item.houseid,
          houseroomid:item.houseroomid
        })
      })
      let data = {
        houselist: list,
        userid: this.userInfo.userid
      }
      housetrusteeship(data).then(res=>{
        if(res.code == 200){
          wx.showToast({
            title: '操作成功',
            icon: 'success',
             success: ()=>{
              // that.isShouquan()
              uni.redirectTo({ url: '/pages/index/index' })
            }
          })
        }else{
           wx.showToast({
            title: res.msg,
            icon: 'none',
            
          })
        }
      })
    },
    isShouquan(){
      let that = this
      wx.login({
        success:(res)=> {
          var code = res.code
          getuseropenid({code}).then(e=>{
            // if(e.data.openid != 'null'){
              wx.setStorageSync('openid', e.data.openid)
              wx.setStorageSync('session_key', e.data.session_key)
              GetUserInfo_openid({openid:e.data.openid}).then(e=>{
                that.isCode = true
                if(e.code == 200){
                  store.commit('baseStore/SET_USERINFO', e.data)
                  setToken(e.data.token)
                }else if(e.code == 300){
                  that.$refs.approve.open()
                }
              }).catch(e=>{
                
              })
            // }else{
            //   that.isCode = false
            //   that.$refs.wxpopup.open()
            // }
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.template {
  @include num();
  background: #F9F9F9;
  display: flex;
  flex-direction: column;
  .bextBtn{
    position: fixed;
    bottom: 10px;
    left: 0;
    right: 0;
    margin: auto;
    width: 345px;
    height: 45px;
    background: linear-gradient(315deg, #FFAA58 0%, #FFBD6C 100%);
    box-shadow: 0px 2px 4px 0px rgba(252, 174, 55, 0.21), 0px 3px 5px 0px rgba(255, 216, 111, 0.14);
    border-radius: 100px;
    text-align: center;
    font-size: 16px;
    font-family: PingFangSC-Semibold, PingFang SC;
    font-weight: 600;
    color: #FFFFFF;
    line-height: 45px;
    text-shadow: 0px 2px 4px rgba(252, 174, 55, 0.21);
    }
  .linkList{
    margin-top: 2px;
    padding-bottom: 56px;
    .list-item{
      background: #fff;
      box-sizing: border-box;
      padding: 15px;
      border-bottom: 2px solid #EFEFEF;
      display: flex;
      flex-direction: row;
    }
    .leftImg{
      width: 110px;
      height: 115px;
      margin-right: 15px;
      position: relative;
      img{
        width: 100%;
        height: 100%;
        border-radius: 4px;
      }
      .leftTop{
        position: absolute;
        top: 0;
        left: 0;
        box-sizing: border-box;
        height: 18px;
        border-radius: 4px 0px 12px 0px;
        font-size: 10px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #FFFFFF;
        line-height: 18px;
        padding: 0 10px;
      }
      
      .red{
        background: #FF6B75;
      }
      .green{
        background: #08C881;
      }
      .yellow{
        background: #FFC72D;
      }
    }
    .rightText{
      flex: 1;
      .text-top{
        height: 44px;
        font-size: 16px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #000000;
        line-height: 22px;
        overflow: hidden;
      }
      .time{
        margin-top: 4px;
        font-size: 14px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #4A4A4A;
        line-height: 20px;
      }
      .money{
        font-size: 12px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #FF5A65;
        line-height: 25px;
        span{
          font-size: 18px;
        }
      }
      .btn{
        margin-top: 4px;
        display: flex;
        div{
          width: 76px;
          height: 24px;
          background: linear-gradient(315deg, #FFAA58 0%, #FFBD6C 100%);
          border-radius: 13px;
          font-size: 14px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #FFFFFF;
          line-height: 24px;
          text-align: center;
        }
        .one{
          margin-right: 10px;
        }
      }
    }
  }
}
.tips{
    width: 335px;
    // height: 174px;
    display: flex;
    flex-direction: column;
    align-items: center;
    border-radius: 10px;
    background-color: #fff;
    position: relative;
    .tips-top{
      height: 22px;
      font-size: 16px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #4A4A4A;
      line-height: 22px;
      margin: 20px 0 30px 0;
    }
    .tips-text{
      // height: 22px;
      font-size: 16px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #6D7278;
      line-height: 22px;
    }
    .tips-btn{
      margin-top: 30px;
      width: 100%;
      border-top: 2px solid #EFEFEF;
      display: flex;
      // position: absolute;
      // bottom: 0;
      div{
        height: 50px;
        width: 50%;
        font-size: 13px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #4A4A4A;
        line-height: 50px;
        text-align: center;
      }
      .btn-closs{
        border-right: 2px solid #EFEFEF;
      }
    }
  }
.tips1{
    width: 335px;
    height: 174px;
    display: flex;
    flex-direction: column;
    align-items: center;
    border-radius: 10px;
    background-color: #fff;
    position: relative;
    .tips-top{
      height: 22px;
      font-size: 16px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #4A4A4A;
      line-height: 22px;
      margin-top: 20px;
    }
    .tips-text{
      margin: 20px 0;
      height: 22px;
      font-size: 16px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #6D7278;
      line-height: 22px;
      padding: 0 20px;
      text-align: center;
    }
    .tips-btn{
      width: 100%;
      border-top: 2px solid #EFEFEF;
      display: flex;
      position: absolute;
      bottom: 0;
      div{
        height: 40px;
        width: 50%;
        font-size: 13px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #4A4A4A;
        line-height: 40px;
        text-align: center;
      }
      .btn-closs{
        border-right: 2px solid #EFEFEF;
      }
    }
  }
.tips2{
    width: 335px;
    height: 174px;
    display: flex;
    flex-direction: column;
    align-items: center;
    border-radius: 10px;
    background-color: #fff;
    position: relative;
    .tips-top{
      height: 22px;
      font-size: 16px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #4A4A4A;
      line-height: 22px;
      margin: 20px 0 30px 0;
    }
    .tips-text{
      height: 22px;
      font-size: 16px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #6D7278;
      padding: 0 20px;
      line-height: 22px;
    }
    .tips-btn{
      width: 100%;
      border-top: 2px solid #EFEFEF;
      display: flex;
      position: absolute;
      bottom: 0;
      div{
        height: 40px;
        width: 50%;
        font-size: 13px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #4A4A4A;
        line-height: 40px;
        text-align: center;
      }
      .btn-closs{
        border-right: 2px solid #EFEFEF;
      }
    }
  }
::v-deep .segmented-control{
  height: 45px;
  background: #FFFFFF;
  .segmented-control__text{
    font-size: 16px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #FFAA58;
    line-height: 45px;
  }
  .segmented-control__item--text{
    border-bottom-width: 3px;
  }
  .segmented-control__item:first-child::after{
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    margin: auto;
    width: 2px;
    height: 20px;
    background-color: #EFEFEF;
    // border: 1px solid ;
  }
}
</style>
